import { request } from "@/utils/service"
import type * as Coupon from "./types/coupon"

/** 获取优惠券列表 */
export function getCouponListApi(params: Coupon.GetCouponRequestData) {
  return request<Coupon.CouponResponseData>({
    url: "/coupon/page",
    method: "get",
    params
  })
}

/** 创建优惠券 */
export function createCouponApi(data: Coupon.CreateCouponRequestData) {
  return request({
    url: "/coupon",
    method: "post",
    data
  })
}

/** 更新优惠券 */
export function updateCouponApi(data: Coupon.UpdateCouponRequestData) {
  return request({
    url: "/coupon",
    method: "put",
    data
  })
}

/** 删除优惠券 */
export function deleteCouponApi(id: number) {
  return request({
    url: `/coupon/${id}`,
    method: "delete"
  })
}

/** 获取优惠券详情 */
export function getCouponDetailApi(id: number) {
  return request<Coupon.CouponData>({
    url: `/coupon/${id}`,
    method: "get"
  })
}

/** 获取用户优惠券列表 */
export function getUserCouponListApi(params: Coupon.GetUserCouponRequestData) {
  return request<Coupon.UserCouponResponseData>({
    url: "/coupon/user-coupon/list",
    method: "get",
    params
  })
}

/** 批量删除优惠券 */
export function batchDeleteCouponApi(ids: number[]) {
  return request({
    url: "/coupon/batch",
    method: "delete",
    data: ids
  })
}